package model;

import java.util.Enumeration;
import java.util.Vector;

import dao.CategoryDAO;
import dao.RommDAO;

public class ListCategory {

	private CategoryDAO categoryDAO;
	private Vector listcategory;

	public ListCategory() {
		listcategory = new Vector();
	}

	public void connect() {

		categoryDAO = new CategoryDAO();
		listcategory = categoryDAO.getListcategory();
	}

	public Vector getListcategory() {
		return listcategory;
	}

	public void setListcategory(Vector listcategory) {
		this.listcategory = listcategory;
	}

	public void addCategory(Category cate) {
		listcategory.add(cate);
		categoryDAO.insert_Category(cate);
	}

	
	public void deleteCategory(Category cate) {
		listcategory.remove(cate);
		categoryDAO.insert_Category(cate);
	}
	
	// search by id
	public Category getCategoryByID(String id) {
		Enumeration emp = listcategory.elements();
		while (emp.hasMoreElements()) {
			Category each = (Category) emp.nextElement();
			if (id.equals(each.getCategory_id())) {
				return each;
			}
		}
		return new Category();
	}
}
